/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogModificarHoraExtra.java
 *
 * Created on 15/04/2011, 11:19:35 PM
 */

package frontera.interfaz.dialogo;

import frontera.interfaz.panel.PanelHorasExtraEmpleado;
import control.SIRHApp;
import entidad.HoraExtra;
import java.util.Calendar;
import java.util.List;
import javax.swing.JButton;

/**
 *
 * @author Silex RPR
 */
public class DialogModificarHoraExtra extends javax.swing.JDialog {

    /** Creates new form DialogModificarHoraExtra */
    public DialogModificarHoraExtra(java.awt.Frame parent, boolean modal, int indice,
            HoraExtra horaExtra, PanelHorasExtraEmpleado pHEE, JButton boton) {
        super(parent, modal);
        initComponents();

        setLocationRelativeTo(null);
        inicializarVariables(indice, horaExtra, pHEE, boton);
    }

    private void inicializarVariables(int indice, HoraExtra horaExtra, PanelHorasExtraEmpleado pHEE, JButton boton){
        DialogModificarHoraExtra.panelHorasExtraEmpleado = pHEE;
        DialogModificarHoraExtra.horaExtra = horaExtra;
        DialogModificarHoraExtra.indice = indice;
        
        labelFecha.setText(DialogModificarHoraExtra.horaExtra.getFecha().get(Calendar.DATE) +
                           "/" +
                           ( DialogModificarHoraExtra.horaExtra.getFecha().get(Calendar.MONTH) + 1) +
                           "/" +
                           DialogModificarHoraExtra.horaExtra.getFecha().get(Calendar.YEAR));
        
        labelTipoHoras.setText(DialogModificarHoraExtra.horaExtra.getTipoHoraExtra().toString());
        labelCantidadHoras.setText(String.valueOf(DialogModificarHoraExtra.horaExtra.getCantidadHoras()));

        DialogModificarHoraExtra.boton = boton;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelFecha = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        botonEliminar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        labelTipoHoras = new javax.swing.JLabel();
        labelCantidadHoras = new javax.swing.JLabel();
        botonAtras = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Actualizando Horas Extras");

        labelFecha.setFont(new java.awt.Font("Dialog", 0, 18));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Cantidad De Horas Extras");

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/hExtra.png"))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Dialog", 1, 18));
        jLabel3.setText("Fecha:");

        botonEliminar.setText("Eliminar");
        botonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Tipo De Horas Extras");

        botonAtras.setText("Atras");
        botonAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAtrasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(botonEliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botonAtras, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelFecha, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelCantidadHoras, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelTipoHoras, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(labelFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelTipoHoras, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelCantidadHoras, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAtras)
                    .addComponent(botonEliminar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarActionPerformed

        List<HoraExtra> horaExtraTemporales = panelHorasExtraEmpleado.getNuevasHorasExtras();
        horaExtraTemporales.remove(horaExtra);

        boton.setBackground(SIRHApp.getInstance().getVentanaPrincipal().getBackground());

        this.setVisible(false);
        this.dispose();

    }//GEN-LAST:event_botonEliminarActionPerformed

    private void botonAtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAtrasActionPerformed
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_botonAtrasActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                DialogModificarHoraExtra dialog = new DialogModificarHoraExtra(new javax.swing.JFrame(), true,indice, horaExtra,
                        panelHorasExtraEmpleado, boton);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAtras;
    private javax.swing.JButton botonEliminar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel labelCantidadHoras;
    private javax.swing.JLabel labelFecha;
    private javax.swing.JLabel labelTipoHoras;
    // End of variables declaration//GEN-END:variables
    private static HoraExtra horaExtra;
    private static int indice;
    private static PanelHorasExtraEmpleado panelHorasExtraEmpleado;
    private static JButton boton;
}
